﻿using Epm.AppLogic.Framework;
using msBsc.Xsd.DataTds;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Xml;
using System.Xml.Linq;
using System.Linq;
using System.Web.Configuration;

namespace msBsc.AppLogic.DataAlc
{
    /// <summary>
    /// 银行卡类型
    /// </summary>
    /// Author:蒲崇彬
    /// Creation date:2015-8-31 13:08
    public class CBizBseBank : CustBizObject
    {
        private CDmBseBank m_CDmBseBank = new CDmBseBank();
        private readonly List<CDmBseBank> _allAreaInfoList = null;
        private CDmBseBank oDmBseBank
        {
            get { return m_CDmBseBank; }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public CBizBseBank()
            : base()
        {
            this.DataObj = new CDbAccess();
            this.DataObj.Init(this.m_CDmBseBank.BSE_BANK);
            this.TableName = this.DataObj.TableName;
            this.DataObj.KeyField = this.DataObj.Fields["BANK_ID"];
        }

        /// <summary>
        /// 新增记录前的处理
        /// </summary>
        /// <param name="drw">新增数据行</param>
        /// <returns>true/false</returns>
        /// <remarks>
        /// 生成ID值
        /// </remarks>
        protected override bool BeforeRowAdded(DataRow drw)
        {
            if (drw[this.KeyFieldName].ToString().Length < 10)
            {
                drw[this.KeyFieldName] = this.DataObj.NewID();
            }
            return true;
        }

        /// <summary>
        /// 记录修改前检验
        /// </summary>
        /// <param name="drw">当前记录</param>
        /// <returns>>校验合法，返回值为true,否则返回false</returns>
        /// <remarks>
        /// ID不允许修改,并把此修改操作记录到BSE_MODIFY_HISTORY表中
        /// </remarks>
        protected override bool BeforeRowModified(DataRow drw)
        {
            //ID不容许修改
            if (drw[this.KeyFieldName].ToString() != drw[this.KeyFieldName, DataRowVersion.Original].ToString())
            {
                Exception e = new Exception(this.TableName + "表的主键" + this.KeyFieldName + "字段不允许被修改");
                throw e;
            }
            return true;
        }
        protected override bool BeforeRowDeletedR(DataRow drw)
        {

            return true;
        }
        protected override bool AfterRowAdded(DataRow drw)
        {
            return true;
        }
        protected override bool AfterRowModified(DataRow drw)
        {
            return true;
        }
        protected override bool AfterRowDeletedR(DataRow drw)
        {
            return true;
        }

        /// <summary>
        /// 获取所有 银行卡类型
        /// </summary>
        /// <returns></returns>
        public DataTable GetBseBankList() {

            DataSet ds = this.DataObj.QueryBySQL("SELECT * FROM [dbo].[BSE_BANK]");
            if (ds!=null&& ds.Tables[0].Rows.Count>0)
            {
                return ds.Tables[0];
            }
            return null;
        }
    }
}
